#pragma once
#include <string>
#include "moogle.h"
#include <GL/glew.h>
#include <GL/gl.h>

namespace moogle
{
  enum SHADER_TYPE
  {
    VERTEX_SHADER = GL_VERTEX_SHADER,
    FRAGMENT_SHADER = GL_FRAGMENT_SHADER,
    GEOMETRY_SHADER = GL_GEOMETRY_SHADER
  };

  class shader
  {
    GLuint _gl_obj;

  public:
    shader(const std::string& src_code, SHADER_TYPE type);
    ~shader();

    static shader from_file(const std::string& src_path);
    static shader from_file(const std::string& src_path, SHADER_TYPE type);

    GLuint gl_obj();
  };

  class shader_program
  {
    GLuint _gl_obj;

    void _init();
    void _attach_shader(shader*);
    void _link();

  public:
    template <typename ForwardIterator>
    shader_program(ForwardIterator begin, ForwardIterator end)
    {
      _init();
      for (auto it = begin; it != end; ++it)
        _attach_shader(*it);
      _link();
    }
    ~shader_program();

    GLuint gl_obj();
  };
}
